# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=recode
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.7.14
pkgrel=1
pkgdesc="Converts files between various character sets and usages (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/rrthomas/recode"
license=('GPL3' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "help2man")
source=("https://github.com/rrthomas/recode/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "01-no-undefined.patch")
sha256sums=('786aafd544851a2b13b0a377eac1500f820ce62615ccc2e630b501e7743b9f33'
            '40c88d6d70c91f2ab2919b77e2d6577cdcc55ec368f8c873cc1a1f1e1b6dc52b')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/01-no-undefined.patch"

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  export lt_cv_deplibs_check_method='pass_all'

  PYTHON="${MINGW_PREFIX}/bin/python3" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --mandir=${MINGW_PREFIX}/share/man \
    --infodir=${MINGW_PREFIX}/share/info \
    --without-libiconv-prefix \
    --without-libintl-prefix

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING-LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING-LIB"
}
